int myAtoi(char *str) {
    unsigned int sum = 0;
    int flag = 1;
    int i = 0;
    while(str[i] == ' ') {
        i++;
    }
    if(str[i] == '+') {
        flag = 1;
        i++;
    } else if(str[i] == '-') {
        flag = -1;
        i++;
    }

    while(str[i] != '\0') {
        if(isdigit(str[i])) {
            if(flag == 1 && sum > 214748364) {
                return 0x7fffffff;
            }
            if(flag == -1 && sum > 214748364) {
                return -2147483648;
            }
            sum = sum * 10 + (str[i] - '0');
            i++;
        } else {
            break;
        }
    }
    if(flag == 1 && sum > 0x7fffffff) {
        return 0x7fffffff;
    }
    if(flag == -1 && sum > 0x7fffffff) {
        return -2147483648;
    }
    return flag * sum;
}